#include <stdbool.h>
#include <stdint.h>

typedef struct CoTask CoTask;

typedef void *(*ProcessFunction)(CoTask *task, void *arg);
typedef enum CoTaskStatus
{
    CO_TASK_STATUS_INIT,
    CO_TASK_STATUS_RUNNING,
    CO_TASK_STATUS_SUSPENDING,
    CO_TASK_STATUS_FINISH,
    CO_TASK_STATUS_INVALID,
} CoTaskStatus;

#define CO_ARG(arg) ((void *)(uintptr_t)arg)
#define CO_CAST(type, arg) ((type)(uintptr_t)arg)

typedef struct CoTaskAttr
{
    uint32_t stackSize;
} CoTaskAttr;

bool CoInitEnvironment();
CoTask *CoCreateTask(const CoTaskAttr *attr, ProcessFunction process, void *arg);
void *CoResumeTask(CoTask *task, void *arg);
void *CoYieldTask(CoTask *task, void *arg);
void *CoExitTask(CoTask *task, void *arg);
void CoDestroyTask(CoTask *task);
CoTaskStatus CoGetTaskStatus(CoTask *task);